package com.vidmt.api.modules.sys.shiro;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

import org.apache.shiro.web.filter.authc.UserFilter;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.vidmt.api.common.exceptions.UserNotLoginException;
import com.vidmt.api.common.pojo.ApiResultServer;

@Service
public class MyApiUserFilter extends UserFilter {
	@Override
	protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
		saveRequest(request);
//		throw new UserNotLoginException();
		response.reset();
		response.setContentType("application/json");
		response.setCharacterEncoding("utf-8");
		ApiResultServer result = new ApiResultServer(new UserNotLoginException());
		response.getWriter().print(JSON.toJSONString(result));
		return false;
	}

}
